package com.powerwyx.shortlink.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.powerwyx.shortlink.project.pojo.dto.ShortLinkGroupStatsDTO;
import com.powerwyx.shortlink.project.pojo.dto.ShortLinkStatsDTO;
import com.powerwyx.shortlink.project.pojo.entity.LinkDeviceStats;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author 17585
* @description 针对表【t_link_device_stats】的数据库操作Mapper
* @createDate 2024-07-11 20:16:43
* @Entity generator.domain.TLinkDeviceStats
*/
public interface LinkDeviceStatsMapper extends BaseMapper<LinkDeviceStats> {

    void shortLinkDeviceStatistics(LinkDeviceStats linkDeviceStats);

    /**
     * 根据短链接获取指定日期内访问设备监控数据
     */
    @Select("SELECT " +
            "    tlds.device, " +
            "    SUM(tlds.cnt) AS cnt " +
            "FROM " +
            "    t_link tl INNER JOIN " +
            "    t_link_device_stats tlds ON tl.full_short_url = tlds.full_short_url " +
            "WHERE " +
            "    tlds.full_short_url = #{param.fullShortUrl} " +
            "    AND tl.gid = #{param.gid} " +
            "    AND tl.del_flag = '0' " +
            "    AND tl.enable_status = #{param.enableStatus} " +
            "    AND tlds.date BETWEEN #{param.startDate} and #{param.endDate} " +
            "GROUP BY " +
            "    tlds.full_short_url, tl.gid, tlds.device;")
    List<LinkDeviceStats> listDeviceStatsByShortLink(@Param("param") ShortLinkStatsDTO shortLinkStatsDTO);



    /**
     * 根据分组获取指定日期内访问设备监控数据
     */
    @Select("SELECT " +
            "    tlds.device, " +
            "    SUM(tlds.cnt) AS cnt " +
            "FROM " +
            "    t_link tl INNER JOIN " +
            "    t_link_device_stats tlds ON tl.full_short_url = tlds.full_short_url " +
            "WHERE " +
            "    tl.gid = #{param.gid} " +
            "    AND tl.del_flag = '0' " +
            "    AND tl.enable_status = '0' " +
            "    AND tlds.date BETWEEN #{param.startDate} and #{param.endDate} " +
            "GROUP BY " +
            "    tl.gid, tlds.device;")
    List<LinkDeviceStats> listDeviceStatsByGroup(@Param("param") ShortLinkGroupStatsDTO shortLinkGroupStatsDTO);

}




